home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / copyConvertSolidTx.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  26.6 KB  |  932 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  Creation Date:  16 September 1997
  22. //  Author:         cdt
  23. //
  24. //  Procedure Name:
  25. //      copyConvertSolidTx
  26. //
  27. //  Description:
  28. //      Procedure to execute convertSolidTx using the contents of the
  29. //      multi-lister highlight list and the selection list. The nodes
  30. //      downstream of the highlighted texture will be duplicated, and
  31. //      the surface on the selection list will be added the new
  32. //      shading group.
  33. //
  34. //      The multi-lister highlight list will be updated to contain the
  35. //      new nodes on successful completion of the command.
  36. //
  37. //  Input Arguments:
  38. //      antiAlias - toggle whether anti-aliasing should be done.
  39. //        edgeQuality - toggle wheter to use uv bounding box test for edge quality.
  40. //      bakeLighting - true if the baked lighting is desired.
  41. //      bakeShadow - true if the baked shadows is desired.
  42. //        bakeAlpha - true if bake alpha is desired
  43. //      doubleSided - true if normals should be flipped to face camera
  44. //        compRange - true if use selected component range
  45. //        uvRange - 0 (unit range), 1 (full range), 2 (use specified)
  46. //        umin,vmin umax, vmax - uv range to use.
  47. //      resX - X resolution of convert solid texture.
  48. //      resY - Y resolution of convert solid texture.
  49. //        fileFormat - saved file format to use.
  50. //
  51. //  Return Value:
  52. //      None.
  53. //
  54.  
  55. proc string plugAttr( string $plug )
  56. {
  57.     string $buffer[];
  58.     tokenize($plug, ".", $buffer);
  59.     return $buffer[1];
  60. }
  61.  
  62. proc string plugNode( string $plug )
  63. {
  64.     string $buffer[];
  65.     tokenize($plug, ".", $buffer);
  66.     return $buffer[0];
  67. }
  68.  
  69. proc addLast( string $itemArray[], string $item )
  70. {
  71.     $itemArray[size($itemArray)] = $item;
  72. }
  73.  
  74. proc removeArrayElement( string $element, string $array[] )
  75. {
  76.     string $tmp[];
  77.  
  78.     for ($item in $array) {
  79.         if ($element != $item)
  80.             addLast($tmp, $item);
  81.     }
  82.  
  83.     clear($array);
  84.  
  85.     for ($i = 0; $i < size($tmp); $i += 1)
  86.         $array[$i] = $tmp[$i];
  87. }
  88.  
  89. proc downStreamConnections( string $node, string $result[] )
  90. {
  91.     string $connections[] = `listConnections -connections true
  92.         -plugs true -source false -destination true $node`;
  93.  
  94.     // Foreach destination (output) connection on node.
  95.  
  96.     for ($i = 0; $i < size($connections); $i += 2) {
  97.         // All message connections are skipped.
  98.  
  99.         if (plugAttr($connections[$i]) != "message") {
  100.             addLast($result, $connections[$i]);
  101.             addLast($result, $connections[$i+1]);
  102.         }
  103.     }
  104. }
  105.  
  106. proc downStreamNetwork( string $node, string $result[] )
  107. {
  108.     // Check if node is already in result.
  109.  
  110.     for ($item in $result) {
  111.         if ($item == $node)
  112.             return;
  113.     }
  114.  
  115.     addLast($result, $node);
  116.  
  117.     // Do a depth first traversal to find the shading group.
  118.  
  119.     if (`objectType $node` == "shadingEngine") {
  120.         if ($node == "initialShadingGroup" || $node == "initialParticleSE")
  121.             error("Cannot convert a texture connected to "+$node);
  122.     }
  123.     else {
  124.         string $connections[];
  125.  
  126.         downStreamConnections($node, $connections);
  127.  
  128.         for ($i = 0; $i < size($connections); $i += 2) {
  129.             string $dstPlug = $connections[$i + 1];
  130.             string $dstNode = plugNode($dstPlug);
  131.             downStreamNetwork($dstNode, $result);
  132.         
  133.         }
  134.     }
  135. }
  136.  
  137. proc addSurfaceToNetwork( string $network[], string $surface )
  138. {
  139.     for ($item in $network) {
  140.         if (`objectType $item` == "shadingEngine") {
  141.             string $buffer[];
  142.             tokenize $surface " " $buffer;
  143.             sets -e -forceElement $item $buffer;
  144.             break;
  145.         }
  146.     }
  147. }
  148.  
  149. proc int countGroupsInNetwork( string $network[] )
  150. {
  151.     int $count = 0;
  152.  
  153.     for ($item in $network)
  154.         if (`objectType $item` == "shadingEngine")
  155.             $count += 1;
  156.  
  157.     return $count;
  158. }
  159.  
  160. proc substituteFileTexture( string $network[],
  161.                             string $oldPlug,
  162.                             string $newFile )
  163. {
  164.     string $connections[] = `listConnections -plugs true -source false
  165.         -destination true $oldPlug`;
  166.  
  167.     // Foreach output connection on the substituted plug
  168.  
  169.     for ($dstPlug in $connections) {
  170.         string $dstNode = plugNode($dstPlug);
  171.  
  172.         // Find the corresponding node in the network.
  173.  
  174.         for ($item in $network) {
  175.             if ($item == $dstNode) {
  176.                 // Break the connection between the network and the
  177.                 // old node, and replace it with a connection to new.
  178.  
  179.                 disconnectAttr $oldPlug $dstPlug;
  180.  
  181.                 // The file attribute used for the connection depends
  182.                 // on the number of children in the destination plug.
  183.  
  184.                 string $attributes[] = `listAttr $oldPlug`;
  185.  
  186.                 int $count = size($attributes);
  187.  
  188.                 if ($count == 4) // parent + 3 children
  189.                     connectAttr ($newFile+".outColor") $dstPlug;
  190.                 else if ($count == 1)
  191.                     connectAttr ($newFile+".outAlpha") $dstPlug;
  192.             }
  193.         }
  194.     }
  195. }
  196.  
  197. proc substituteNode(string $network[], string $old, string $new )
  198. {
  199.     string $connections[] = `listConnections -connections true
  200.         -plugs true -source false -destination true $old`;
  201.  
  202.     // Foreach output connection on the substituted node.
  203.  
  204.     for ($i = 0; $i < size($connections); $i += 2) {
  205.         string $srcPlug = $connections[$i];
  206.         string $dstPlug = $connections[$i + 1];
  207.         string $dstNode = plugNode($dstPlug);
  208.  
  209.         // Find the corresponding node in the network.
  210.  
  211.         for ($item in $network) {
  212.             if ($item == $dstNode) {
  213.                 // Break the connection between the network and the
  214.                 // old node, and replace it with a connection to new.
  215.  
  216.                 disconnectAttr $srcPlug $dstPlug;
  217.  
  218.                 // Make the new connection instead
  219.  
  220.                 connectAttr ($new+"."+plugAttr($srcPlug)) $dstPlug;
  221.             }
  222.         }
  223.     }
  224. }
  225.  
  226. proc string[] duplicateNetwork( string $network[] )
  227. {
  228.     string $newNetwork[];
  229.  
  230.     // Are there nodes to duplicate?
  231.  
  232.     if (size($network) > 0) {
  233.         string $duplicateCmd = "duplicate -inputConnections";
  234.  
  235.         // There is currently a bug in duplicate with input connections,
  236.         // the specified nodes must be sorted by the depth (ie. from texture
  237.         // to shader to shading group or leaf to root).
  238.         //
  239.         // In convert solid, the network was produced by invoking
  240.         // downstreamNetwork which will produce the a list in the correct
  241.         // order.
  242.  
  243.         for ($node in $network)
  244.             $duplicateCmd += " " + $node;
  245.  
  246.         $newNetwork = `eval($duplicateCmd)`;
  247.     }
  248.  
  249.     return $newNetwork;
  250. }
  251.  
  252. proc string getUvRangeArgs(
  253.     int $uvRange, float $umin, float $vmin, float $umax, float $vmax )
  254. {
  255.     string $args = " ";
  256.     
  257.     if ($uvRange == 0) { // unit
  258.         $args = " ";
  259.     }
  260.     else if ($uvRange == 1) { // full
  261.         $args = " -fullUvRange ";
  262.     }
  263.     else if ($uvRange == 2) { // set
  264.         $args = (" -uvRange " + $umin + " " + $umax + " " + $vmin + " " + $vmax + " ");
  265.     }
  266.  
  267.     return $args;
  268. }
  269.  
  270. proc doConvertTexture(string $command,
  271.        string $surface, string $component, string $texture,
  272.        string $result[] )
  273. {
  274.     // Get all connections downstream from the texture including
  275.     // itself. If the texture is a bump node we generate the
  276.     // connections to reflect the texture connected to the bump.
  277.     //
  278.  
  279.     string $connections[];
  280.  
  281.     string $type = `objectType $texture`;
  282.  
  283.     if ($type == "bump2d" || $type == "bump3d") {
  284.         string $bumpPlug = $texture+".bumpValue";
  285.         $connections = `listConnections -plugs true $bumpPlug`;
  286.         addLast($connections, $bumpPlug);
  287.     }
  288.     else {
  289.         downStreamConnections($texture, $connections);
  290.     }
  291.  
  292.     // Determine the minimum number of nodes to duplicate.
  293.     //
  294.  
  295.     string $network[];
  296.  
  297.     for ($i = 0; $i < size($connections); $i += 2) {
  298.         string $dstPlug = $connections[$i + 1];
  299.         string $downStreamNode = plugNode($dstPlug);
  300.         string $dstType = `objectType $downStreamNode`;
  301.  
  302.         if ($dstType == "bump2d" || $dstType == "bump3d") {
  303.             downStreamNetwork($downStreamNode, $network);
  304.  
  305.             // Remove the bump node from network.
  306.  
  307.             removeArrayElement($downStreamNode, $network);
  308.         }
  309.         else {
  310.             downStreamNetwork($downStreamNode, $network);
  311.         }
  312.     }
  313.  
  314.     if (countGroupsInNetwork($network) > 1) {
  315.         error($texture+" is connected to more than one shading group");
  316.     }
  317.  
  318.     string $newNetwork[] = duplicateNetwork($network);
  319.  
  320.     // If we have components all of them will be converted and assigned
  321.     // to the new shading group; otherwise, act on the surface.
  322.     string $object;
  323.     if (size($component))
  324.         $object = $component;
  325.     else
  326.         $object = $surface;
  327.  
  328.     addSurfaceToNetwork($newNetwork, $object);
  329.  
  330.     for ($newNode in $newNetwork)
  331.         addLast($result, $newNode);
  332.  
  333.     // Now run convert solid texture on each channel.
  334.     //
  335.     for ($i = 0; $i < size($connections); $i += 2) {
  336.         string $srcPlug = $connections[$i];
  337.         string $dstPlug = $connections[$i + 1];
  338.         string $downStreamNode = plugNode($dstPlug);
  339.  
  340.         string $dstType = `objectType $downStreamNode`;
  341.  
  342.         string $evalStr = $command + $srcPlug + " " + $object ;
  343.         string $fileTextures[] = evalEcho( $evalStr );
  344.         string $newFile = $fileTextures[0]; // there is only one
  345.  
  346.         if ($dstType == "bump2d" || $dstType == "bump3d") {
  347.             // Connect the file and new bump.
  348.  
  349.             string $newBump = `shadingNode -asUtility bump2d`;
  350.             float $depth = `getAttr ($downStreamNode+".bumpDepth")`;
  351.             setAttr ($newBump+".bumpDepth")  $depth;
  352.             connectAttr ($newFile+".outAlpha") ($newBump+".bumpValue");
  353.  
  354.             substituteNode($newNetwork, $downStreamNode, $newBump);
  355.  
  356.             // Append the new nodes to result.
  357.  
  358.             addLast($result, $newFile);
  359.  
  360.             addLast($result, $newBump);
  361.         }
  362.         else {
  363.             substituteFileTexture($newNetwork, $srcPlug, $newFile);
  364.  
  365.             // Append the new nodes to result.
  366.  
  367.             addLast($result, $newFile);
  368.         }
  369.     }
  370. }
  371.  
  372. proc doConvertShader(string $command,
  373.       string $surface, string $component, string $shader,
  374.       string $result[] )
  375. {
  376.     // Get all nodes downstream and including the shader.
  377.     //
  378.  
  379.     string $network[];
  380.  
  381.     downStreamNetwork($shader, $network);
  382.  
  383.     if (countGroupsInNetwork($network) > 1) {
  384.         error($shader+" is connected to more than one shading group");
  385.     }
  386.  
  387.     // Get all incoming connections to the shader. Convert solid
  388.     // texture will be run on each of these channels.
  389.     //
  390.  
  391.     string $connections[];
  392.  
  393.     $connections = `listConnections -destination false -source true
  394.         -plugs true $shader`;
  395.  
  396.     // Get only the unique connections.
  397.     //
  398.  
  399.     string $uniqueConnections[];
  400.  
  401.     for ($item in $connections) {
  402.         int $found = false;
  403.  
  404.         for ($uniqueItem in $uniqueConnections) {
  405.             if ($item == $uniqueItem) {
  406.                 $found = true;
  407.                 break;
  408.             }
  409.         }
  410.  
  411.         if (!$found)
  412.             addLast($uniqueConnections, $item);
  413.     }
  414.  
  415.     string $newNetwork[] = duplicateNetwork($network);
  416.  
  417.     // If we have components all of them will be converted and assigned
  418.     // to the new shading group; otherwise, act on the surface.
  419.     string $object;
  420.     if (size($component))
  421.         $object = $component;
  422.     else
  423.         $object = $surface;
  424.  
  425.     addSurfaceToNetwork($newNetwork, $object);
  426.  
  427.     // Execute convert solid on each input
  428.  
  429.     for ($texturePlug in $uniqueConnections) {
  430.         string $textureNode = plugNode($texturePlug);
  431.  
  432.         string $textureType = `objectType $textureNode`;
  433.  
  434.         if ($textureType == "bump2d" || $textureType == "bump3d") {
  435.  
  436.             string $evalStr = $command + ($textureNode+".bumpValue") + " " + $object;
  437.             string $fileTextures[] = evalEcho( $evalStr );
  438.  
  439.             string $newFile = $fileTextures[0]; // there is only one
  440.  
  441.             string $newBump = `shadingNode -asUtility bump2d`;
  442.             float $depth = `getAttr ($textureNode+".bumpDepth")`;
  443.             setAttr ($newBump+".bumpDepth")  $depth;
  444.             connectAttr ($newFile+".outAlpha") ($newBump+".bumpValue");
  445.  
  446.             substituteNode($newNetwork, $textureNode+".outNormal", $newBump);
  447.  
  448.             // Append the new nodes to result
  449.  
  450.             addLast($result, $newFile);
  451.  
  452.             addLast($result, $newBump);
  453.         }
  454.         else {
  455.             string $evalStr = $command + $texturePlug + " " + $object;
  456.             string $fileTextures[] = evalEcho( $evalStr );
  457.  
  458.             string $newFile = $fileTextures[0]; // there is only one
  459.  
  460.             substituteFileTexture($newNetwork, $texturePlug, $newFile);
  461.  
  462.             // Append the new nodes to result
  463.  
  464.             addLast($result, $newFile);
  465.         }
  466.     }
  467.  
  468.     // Append the new nodes to result
  469.  
  470.     for ($newNode in $newNetwork)
  471.         addLast($result, $newNode);
  472. }
  473.  
  474. proc doConvertBakeLighting(string $command,
  475.             string $surface, string $component, string $shadingGroup,
  476.             string $result[], int $bakeAlpha )
  477. {
  478.     string $connections[] = `listConnections -plugs true
  479.         ($shadingGroup+".surfaceShader")`;
  480.  
  481.     if (size($connections) != 1)
  482.         error($shadingGroup+" does not have a surface shader");
  483.  
  484.     string $srcPlug = $connections[0];
  485.  
  486.     // The network contains only the shading group.
  487.  
  488.     string $network[];
  489.  
  490.     addLast($network, $shadingGroup);
  491.  
  492.     // If we have components all of them will be converted and assigned
  493.     // to the new shading group; otherwise, act on the surface.
  494.     string $object;
  495.     if (size($component))
  496.         $object = $component;
  497.     else
  498.         $object = $surface;
  499.  
  500.     // Execute convert solid texture on the surface.
  501.  
  502.     string $evalStr = $command + $shadingGroup + " " + $object;
  503.     string $fileTextures[] = evalEcho( $evalStr );
  504.  
  505.     string $newFile = $fileTextures[0]; // there is only one
  506.  
  507.     string $newNetwork[] = duplicateNetwork($network);
  508.  
  509.     addSurfaceToNetwork($newNetwork, $object);
  510.  
  511.     {
  512.         // Create a surface shader and insert it between the file texture
  513.         // and the shading group. BUG 144623
  514.         //
  515.  
  516.         string $newShader = `shadingNode -asShader surfaceShader`;
  517.  
  518.         addLast($newNetwork, $newShader);
  519.  
  520.         connectAttr ($newFile+".outColor") ($newShader+".outColor");
  521.         if( $bakeAlpha == 1 ){
  522.  
  523.             // If baking alpha, connect outTransparency of file texture to
  524.             // that of the surface shader.  Fixes bug #185477.
  525.             //
  526.  
  527.             connectAttr ($newFile+".outTransparency")
  528.                         ($newShader+".outTransparency");
  529.         }
  530.  
  531.         substituteFileTexture($newNetwork, $srcPlug, $newShader);
  532.     }
  533.  
  534.     // Append the new nodes to result.
  535.  
  536.     addLast($result, $newFile);
  537.  
  538.     for ($newNode in $newNetwork)
  539.         addLast($result, $newNode);
  540. }
  541.  
  542. proc getBaseClasses( string $nodeType, string $result[] )
  543. {
  544.     string $classes[];
  545.     string $codedClassification[] = `getClassification $nodeType`;
  546.     tokenize($codedClassification[0], ":", $classes);
  547.  
  548.     for ($class in $classes) {
  549.         string $buffer[];
  550.         tokenize($class, "/", $buffer);
  551.         addLast($result, $buffer[0]);
  552.     }
  553. }
  554.  
  555. global proc copyConvertSolidTx( 
  556.     int $antiAlias, 
  557.     int $backMode,
  558.     int $backColorR,
  559.     int $backColorG,
  560.     int $backColorB,
  561.     int $fillTextureSeams,
  562.     int $bakeLighting,
  563.     int $bakeShadow,
  564.     int $bakeAlpha, 
  565.     int $doubleSided, 
  566.     int $compRange,
  567.     int $uvRange, 
  568.     float $umin, float $vmin, float $umax, float $vmax,
  569.     int $resX, 
  570.     int $resY,
  571.     string $fileName,
  572.     string $fileFormat,
  573.     int $useMultilisterHighlighted)
  574. {
  575.     string $surfaces[], $node = "";
  576.     string $components[];
  577.  
  578.     // Get the surfaces and texture from the selection.
  579.     //
  580.  
  581.     string $selection[] = `ls -showType -selection`;
  582.  
  583.     for ($i = 0; $i < size($selection); $i += 2) {
  584.         string $selectNode = $selection[$i];
  585.         string $origString = $selectNode;
  586.         string $type = $selection[$i + 1];
  587.     
  588.         if ($type == "nurbsSurface" || $type == "mesh" || $type == "subdiv" ||
  589.             $type == "transform" || $type == "float3" || $type == "polyFaces")
  590.         {
  591.             // See if we have any components. If so strip out the surface
  592.             // part of it before adding to $surfaces, and store append
  593.             // the component part of it to the corresponding 
  594.             // $component entry
  595.             //
  596.             int $haveComponents = 0;
  597.             string $selectComponent = "";
  598.             string $buffer[];
  599.             int $numTokens = `tokenize $selectNode "." $buffer`;
  600.             
  601.             // We extract out the surface, if components are selected
  602.             if ($numTokens > 1)
  603.             {
  604.                 $haveComponents = 1;
  605.                 $selectNode = $buffer[0];
  606.                 $selectComponent = $buffer[1];
  607.             }
  608.  
  609.             if ($haveComponents)
  610.             {
  611.                 int $existingEntry = -1;
  612.                 for ($s=0; $s<size($surfaces); $s++)
  613.                 {
  614.                     if ($surfaces[$s] == $selectNode)
  615.                     {
  616.                         $existingEntry = $s;
  617.                         break;
  618.                     }
  619.                 }
  620.                 // Add new surface item
  621.                 //
  622.                 if ($existingEntry == -1)
  623.                 {
  624.                     addLast($surfaces, $selectNode);
  625.                     addLast($components, $origString);
  626.                 }
  627.                 
  628.                 // Add to existing surface list
  629.                 //
  630.                 else
  631.                 {
  632.                     $components[$s] = ($components[$s] + " " + $origString);
  633.                 }
  634.             }
  635.             else
  636.             {
  637.                 $selectComponent = "";
  638.                 addLast($surfaces, $selectNode);
  639.                 addLast($components, $selectComponent);
  640.             }
  641.         }
  642.         else {
  643.             string $classes[];
  644.  
  645.             getBaseClasses($type, $classes);
  646.  
  647.             for ($class in $classes) {
  648.                 if ($class == "texture" || $class == "utility" ||
  649.                     $class == "shader" || $class == "shadingEngine")
  650.                 {
  651.                     if ($node != "") {
  652.                         error("Only one shading node can be converted,"+
  653.                               " there is more than one selected");
  654.                     }
  655.  
  656.                     $node = $selectNode;
  657.  
  658.                     break;
  659.                 }
  660.                 else {
  661.                     error($selectNode+" is not a shading node");
  662.                 }
  663.             }
  664.         }
  665.     }
  666.  
  667.     if (size($surfaces) == 0)
  668.         error("No surfaces selected, unable to continue");
  669.  
  670.     // Get the texture from multi-lister if a node has not been specified.
  671.     //
  672.  
  673.     string $currentLister = "";
  674.  
  675.     if ($node == "" && $useMultilisterHighlighted) {
  676.         string $editors[] = `lsUI -editors`;
  677.  
  678.         for ($item in $editors) {
  679.             if (`listerEditor -exists $item`) {
  680.                 string $highlight[] = `listerEditor -q -highlight $item`;
  681.  
  682.                 if (size($highlight) == 1) {
  683.                     $node = $highlight[0];
  684.                     $currentLister = $item;
  685.                     break;
  686.                 }
  687.                 else if (size($highlight) > 1) {
  688.                     error("Only one shading node can be converted,"+
  689.                           " there is more than one highlighted");
  690.                 }
  691.             }
  692.         }
  693.     }
  694.  
  695.     if ($node == "") {
  696.         error("Select or highlighted a shading node, unable to continue");
  697.     }
  698.  
  699.     // Determine the type of node to be converted.
  700.     //
  701.  
  702.     int $isGroup = false;
  703.     int $isTexture = false;
  704.     int $isShader = false;
  705.  
  706.     string $nodeType = `objectType $node`;
  707.  
  708.     if ($bakeLighting) {
  709.         if ($nodeType != "shadingEngine") {
  710.             // Remember the original node for error reporting.
  711.  
  712.             string $originalNode = $node;
  713.  
  714.             // Find the shading group, ensure its unique
  715.  
  716.             string $network[];
  717.  
  718.             downStreamNetwork($node, $network);
  719.  
  720.             int $groupCount = 0;
  721.  
  722.             for ($item in $network) {
  723.                 if (`objectType $item` == "shadingEngine") {
  724.                     $groupCount = $groupCount + 1;
  725.  
  726.                     $node = $item;
  727.  
  728.                     $nodeType = "shadingEngine";
  729.                 }
  730.             }
  731.  
  732.             // Make sure there is only one shading group
  733.  
  734.             if ($groupCount == 0) {
  735.                 error("Unable to bake lighting for "+$originalNode+", there"+
  736.                       " is no shading group connected");
  737.             }
  738.             else if ($groupCount > 1) {
  739.                 error("Unable to bake lighting for "+$originalNode+", there"+
  740.                       " are "+$groupCount+" shading groups connected");
  741.             }
  742.         }
  743.     }
  744.     else {
  745.         // Bake lighting is off.
  746.  
  747.         if ($nodeType == "shadingEngine") {
  748.             // The user probably mean't to run this on the shader not
  749.             // the shading group. Use the node connected to the
  750.             // surface shader attribute instead.
  751.  
  752.             string $connections[];
  753.             $connections = `listConnections ($node+".surfaceShader")`;
  754.  
  755.             if (size($connections) > 0) {
  756.                 $node = $connections[0];
  757.  
  758.                 $nodeType = `objectType $node`;
  759.             }
  760.         }
  761.     }
  762.  
  763.     if ($nodeType == "layeredShader") {
  764.         // The layered shader is special because it may contain other
  765.         // shader nodes upstream. We will be unable to to convert the
  766.         // lighting component on these.
  767.  
  768.         int $layeredType = `getAttr ($node+".compositingFlag")`;
  769.  
  770.         if ($layeredType != 1) {
  771.             error("Unable to convert "+$node+", re-organize your network"+
  772.                   " to use a layered texture instead of a layered shader"+
  773.                   " or use the baked lighting option");
  774.         }
  775.     }
  776.  
  777.     string $classes[];
  778.  
  779.     getBaseClasses($nodeType, $classes);
  780.  
  781.     for ($class in $classes) {
  782.         if ($class == "shadingEngine") {
  783.             $isGroup = true;
  784.         }
  785.         else if ($class == "texture" || $class == "utility") {
  786.             $isTexture = true;
  787.         }
  788.         else if ($class == "shader") {
  789.             $isShader = true;
  790.         }
  791.     }
  792.  
  793.     if ($bakeLighting && !$isGroup) {
  794.         error($node+" is not a shading group, convert with baked lighting"+
  795.               " can only be done on a shading group");
  796.     }
  797.  
  798.     if (!$isGroup && !$isTexture && !$isShader) {
  799.         error($node+" is not a shading node, unable to continue");
  800.     }
  801.  
  802.     // Convert the file format string properly.
  803.     string $format;
  804.     if ($fileFormat == "PIX" || $fileFormat == "ALS") {
  805.         $format = "als";
  806.     }
  807.     else if ($fileFormat == "Bitmap" || $fileFormat == "BMP") {
  808.         $format = "bmp"; 
  809.     }
  810.     else if ($fileFormat == "GIF") {
  811.         $format = "gif"; 
  812.     }
  813.     else if ($fileFormat == "IFF") {
  814.         $format = "iff";
  815.     }
  816.     else if ($fileFormat == "JPG") {
  817.         $format = "jpg";
  818.     }
  819.     else if ($fileFormat == "RLA") {
  820.         $format = "rla"; 
  821.     }
  822.     else if ($fileFormat == "SGI") {
  823.         $format = "sgi"; 
  824.     }
  825.     else if ($fileFormat == "SoftImage" || $fileFormat == "PIC") {
  826.         $format = "si"; 
  827.     }
  828.     else if ($fileFormat == "TIFF" || $fileFormat == "TIF") {
  829.         $format = "tif"; 
  830.     }
  831.     else if ($fileFormat == "Targa" || $fileFormat == "TGA") {
  832.         $format = "tga";
  833.     }
  834.     else if($fileFormat == "Photoshop"){
  835.         $format = "psd";
  836.     }
  837.     else if($fileFormat == "PNG"){
  838.         $format = "png";
  839.     }
  840.     else if($fileFormat == "MacPaint"){
  841.         $format = "pntg";
  842.     }
  843.     else {
  844.         // Some file formats are still suported but are now unavailable
  845.         // in the UI. Futhermore, quantel is no longer supported. (BUG 163640)
  846.         
  847.         if ($fileFormat == "Cineon") {
  848.             $format = "cin";
  849.         }
  850.         else if ($fileFormat == "EPS") {
  851.             $format = "eps";
  852.         }
  853.         else {
  854.             warning ("The file format "+$fileFormat+
  855.                 " is not supported, using IFF");
  856.  
  857.             $format = "iff";
  858.         }
  859.     }
  860.  
  861.     // Do the appropriate convert solid depending on whether its a
  862.     // texture, shader, or shading group.
  863.     //
  864.  
  865.     string $newNodes[];
  866.  
  867.     string $uvrangeStr = getUvRangeArgs($uvRange, $umin, $vmin, $umax, $vmax);
  868.     string $command = "convertSolidTx -antiAlias " + $antiAlias 
  869.         + " -bm " + $backMode
  870.         + " -fts " + $fillTextureSeams
  871.         + " -sh " + $bakeShadow 
  872.         + " -alpha " + $bakeAlpha 
  873.         + " -doubleSided " + $doubleSided 
  874.         + " -componentRange " + $compRange  
  875.         + " -resolutionX " + $resX 
  876.         + " -resolutionY " + $resY 
  877.         + " -fileFormat \"" + $format + "\" "
  878.         + $uvrangeStr + " ";
  879.  
  880.     if ($backMode == 2)
  881.         $command = $command + 
  882.             "-bc " + $backColorR + " " + $backColorG + " " + $backColorB + " ";
  883.  
  884.     if ($fileName != "")
  885.         $command = $command + "-fin \"" + $fileName + "\" ";
  886.  
  887.     for ($s = 0; $s< size($surfaces); $s++) 
  888.     {
  889.         $surface = $surfaces[$s];
  890.         $component = $components[$s];
  891.  
  892.         if ($isTexture) {
  893.             doConvertTexture($command, $surface, $component, $node, $newNodes);
  894.         }
  895.         else if ($isShader) {
  896.             doConvertShader($command, $surface, $component, $node, $newNodes);
  897.         }
  898.         else if ($isGroup) {
  899.             doConvertBakeLighting($command, $surface, $component, $node, $newNodes, $bakeAlpha );
  900.         }
  901.     }
  902.  
  903.     // Highlight or select the created nodes.
  904.     //
  905.  
  906.     if (size($newNodes) > 0) {
  907.         // Did we get the node from the multi-lister?
  908.  
  909.         if ($currentLister != "") {
  910.             string $highlightArgs = "";
  911.  
  912.             for ($item in $newNodes) {
  913.                 $highlightArgs += " -highlight " + $item;
  914.             }
  915.  
  916.             listerEditor -e -clearHighlight $currentLister;
  917.  
  918.             eval("listerEditor -e"+$highlightArgs+" "+$currentLister);
  919.         }
  920.         else {
  921.             string $selectArgs = "";
  922.  
  923.             for ($item in $newNodes) {
  924.                 $selectArgs += " " + $item;
  925.             }
  926.  
  927.             eval("select"+$selectArgs);
  928.         }
  929.     }
  930. }
  931.  
  932.